#!/usr/bin/env bash

help(){
    cat<<__EOF__
Usage: m printer [OPTION]

Description: Manage printers on the system

Options:
  --help      Show this help message
  --settings  Show printer settings
  --names     Show printer names on the system
  --queue     Show items in the printer queue
  --drivers   Show all printer drivers
  --open-web       Enable and show web interface for printers
__EOF__
}

case $1 in
    help)
        help
        ;;
    --settings)
        /usr/bin/lpoptions -l
        ;;
    --name)
        lpstat -p | awk '{print $2}'
        ;;
    --queue)
        lpstat -p | awk '{print $2}' | xargs -n1 lpq -P
        ;;
    --drivers)
        lpinfo -m
        ;;
    --open-web)
        cupsctl WebInterface=yes && open http://localhost:631/printers
        ;;
    *)
        help
        ;;
esac
